﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Text.RegularExpressions;

namespace TVC_WEB.Global
{
    public partial class Login : System.Web.UI.Page
    {
        String sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["Username"] != null && Session["Username"] != "")
            {
                Response.Redirect("User.aspx");
            }
            lbvademail.Text = hdFlag.Value;

            //if(lbvademail.Text=="")
            //    jerror.Attributes["style"] = "display: none";
            //else
            //    jerror.Attributes["style"] = "";
        }

        protected void txtContinue_Click(object sender, EventArgs e)
        {

            BUS.UserControl userctr = new BUS.UserControl();
            DTO.UserInfo userinf = new DTO.UserInfo();

            if (userctr.IsExist_Users_Name(txtEmail.Text))
            {
                userinf = userctr.Get_Users_Email(txtEmail.Text, ref sErr);
                if (userinf.Password.Trim() != txtPass.Text.Trim())
                {
                    hdFlag.Value = "Password is wrong !!!";
                    lbvademail.Text = hdFlag.Value;
                }
                else
                {
                    hdFlag.Value = "";
                    lbvademail.Text = hdFlag.Value;
                    Session["Username"] = txtEmail.Text;
                    Response.Redirect("User.aspx");
                }
            }
            else
            {
                hdFlag.Value = "Email is not existed !!!";
                lbvademail.Text = hdFlag.Value;
            }


        }

        protected void txtEmail_TextChanged(object sender, EventArgs e)
        {

            if (!Regex.IsMatch(txtEmail.Text, @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)"))
            {
                hdFlag.Value = "Email không tồn tại....";
                lbvademail.Text = hdFlag.Value;
            }
            else
            {
                hdFlag.Value = "";
                lbvademail.Text = hdFlag.Value;

            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void txtEmailnew_TextChanged(object sender, EventArgs e)
        {
            
            if (!Regex.IsMatch(txtEmailnew.Text, @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)"))
            {
                hdFlag.Value = "Email không tồn tại....";
                lbvademail.Text = hdFlag.Value;
            }
            else
            {
                hdFlag.Value = "";
                lbvademail.Text = hdFlag.Value;
            }
            
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            if (txtEmailnew.Text != "")
            {
                BUS.UserControl userctr = new BUS.UserControl();
                DTO.UserInfo userinf = new DTO.UserInfo();
                if (userctr.IsExist_Users_Name(txtEmailnew.Text))
                {
                    hdFlag.Value = "Email is existed !!!";
                    lbvademail.Text = hdFlag.Value;

                }
                else if (lbvademail.Text == "")
                {

                    Session["Usernamenew"] = txtEmailnew.Text;
                    Response.Redirect("Register.aspx");
                }

            }
        }
    }
}
